%% theta must be a column vector
function M = vec_to_mat(theta,p,n,c,rc)
if c ~= 0
    np = (n*p+c);
else
    np = (n*p);
end   
if rc==1
    theta = theta'; %% if stacking columns 
    for i = 1:n
        M(i,:) = theta((i-1)*np+1:i*np); %% inverse of stacking rows operator
        %M(:,i) = theta((i-1)*n+1:i*n);        %% inverse of stacking columns operator
    end
elseif rc==2
    for i=1:n
        M(:,i) = theta((i-1)*np+1:i*np);
    end
end 